
package com.zjff.myshop.front.controller;


import com.zjff.myshop.front.pojo.vo.HomeCarouselVO;
import com.zjff.myshop.front.pojo.vo.HomeGoodsVO;
import com.zjff.myshop.front.pojo.vo.HomeInfoVO;
import com.zjff.myshop.common.Constants;
import com.zjff.myshop.common.HomeTypeEnum;
import com.zjff.myshop.front.service.HomeService;
import com.zjff.myshop.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@CrossOrigin
@RestController
@Api(value = "v1", tags = "01.首页模块", position = 3)
@RequestMapping("/app/v1/home")
public class HomeController {

    @Resource
    private HomeService homeService;

    /**
     * 查询首页数据
     */
    @ApiOperation(value = "查询首页数据", notes = "轮播图、新品、推荐等")
    @GetMapping("/index")
    public Result<HomeInfoVO> homeIndex() {
        HomeInfoVO homeInfoVO = new HomeInfoVO();
        HashMap<String, Object> map = new HashMap<>();
        //首页轮播
        map.put("number", Constants.HOME_CAROUSEL_NUMBER);
        map.put("typeId", HomeTypeEnum.HOME_CAROUSEL.getId());
        List<HomeCarouselVO> carouselList = homeService.selectCarouselVOList(map);

        //首页热销商品
        map.put("number", Constants.HOME_GOODS_HOT_NUMBER);
        map.put("typeId", HomeTypeEnum.HOME_GOODS_HOT.getId());
        List<HomeGoodsVO> hotGoodsList = homeService.selectGoodsVOList(map);

        //首页新品上线
        map.put("number", Constants.HOME_GOODS_NEW_NUMBER);
        map.put("typeId", HomeTypeEnum.HOME_GOODS_NEW.getId());
        List<HomeGoodsVO> newGoodsList = homeService.selectGoodsVOList(map);

        //首页为您推荐
        map.put("number", Constants.HOME_GOODS_RECOMMOND_NUMBER);
        map.put("typeId", HomeTypeEnum.HOME_GOODS_RECOMMOND.getId());
        List<HomeGoodsVO> recommendGoodsList = homeService.selectGoodsVOList(map);

        homeInfoVO.setCarouselList(carouselList);
        homeInfoVO.setHotGoodsList(hotGoodsList);
        homeInfoVO.setNewGoodsList(newGoodsList);
        homeInfoVO.setRecommendGoodsList(recommendGoodsList);
        return Result.ok(homeInfoVO);
    }
}
